<template>
  <div id="#app">
    <mt-header :title="$route.meta.title">
      <router-link to="" slot="left" v-show="Backoff" >
        <!-- a链接不可以加事件 -->
      <mt-button icon="back" @click="goBack()">返回</mt-button>
      </router-link>
    </mt-header>

    <div class="contains">
      <transition name="fade">
        <router-view/>
      </transition>
    </div>
    <tabbar></tabbar>
  </div>
</template>

<script>
import tabbar from './components/tabbar.vue'

export default {
  created () {
    if (this.$route.path === '/home') {
      this.Backoff = false
    } else {
      this.Backoff = true
    }
    this.checkLogin()
  },
  components: { tabbar },
  data () {
    return { Backoff: false }
  },
  methods: {
    goBack () {
      this.$router.go(-1)
    },
    checkLogin () {
      this.$http.get('user').then((res) => {
        console.log(res.data)
        console.log(this.$auth.getAuthorization)
        if (res.data.code === 1) {
          // 登陆成功
          this.$store.commit('user/setUser', res.data.data)
        }
      })
    }
  },
  // watch不用this,route是路由里面的信息,router是replace(),go()
  // watch(
  // watch有两个参数,第一个是新的变化数据,第二个旧的数据
  // "$route.path"(new){}
  // ){}
  watch: {
    '$route.path' (newpath) {
      if (newpath !== '/home') {
        this.Backoff = true
        console.log(this.Backoff)
      } else {
        this.Backoff = false
        console.log(this.Backoff)
      }
    }
  }
}
</script>

<style lang="scss" scoped>

.contains{
padding: 0px 0 50px 0;
overflow-x: hidden;
}
.fade-enter {
  opacity: 0;
  transform: translateX(100%)
}
.fade-leave-to {
  opacity: 0;
  transform: translateX(-100%);
  position: absolute;
}
.fade-enter-active, .fade-leave-active {
  transition:all .5s ease;
}
</style>
